/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				Metric Troops
 
Function						: 				Holding the metrics for Troops. Used in 
												the distance calculation for CBR
****************************************************************************/
package cbr.metrics;

import base.WargusPlayer;
import base.WargusStateImporter;
import base.WargusUnit;

public class MetricTroops {
	float m_numFighter;
	float m_numArcher;
	float m_numPeasant;
	float m_numGroundTroops;
	float m_numAirTroops;
	float m_numOceanTroops;
	
	public void setnumFighter(float val){m_numFighter = val;}
	public void setnumArcher(float val){m_numArcher = val;}
	public void setnumPeasant(float val){m_numPeasant = val;}
	public void setnumGroundTroops(float val){m_numGroundTroops = val;}
	public void setnumAirTroops(float val){m_numAirTroops = val;}
	public void setnumOceanTroops(float val){m_numOceanTroops = val;}

	public float getnumFighter(){return m_numFighter;}
	public float getnumArcher(){return m_numArcher;}
	public float getnumPeasant(){return m_numPeasant;}
	public float getnumGroundTroops(){return m_numGroundTroops;}
	public float getnumAirTroops(){return m_numAirTroops;}
	public float getnumOceanTroops(){return m_numOceanTroops;}
	
	public MetricTroops() {
		m_numFighter = 0;
		m_numArcher = 0;
		m_numPeasant = 0;
		m_numGroundTroops = 0;
		m_numAirTroops = 0;
		m_numOceanTroops = 0;				
	}	
	
	public MetricTroops(WargusPlayer p) {
		m_numFighter = 0;
		m_numArcher = 0;
		m_numPeasant = 0;
		m_numGroundTroops = 0;
		m_numAirTroops = 0;
		m_numOceanTroops = 0;		
		
		for(WargusUnit u : p.getUnits())
		{
			if(u.getType()==WargusStateImporter.unitTypeToInteger("peasant") ||
			   u.getType()==WargusStateImporter.unitTypeToInteger("peon")) {
				m_numPeasant++;
			}
			else if(u.getType()==WargusStateImporter.unitTypeToInteger("footman") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("grunt") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("ballista") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("catapult") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("archer") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("axethrower")) {
				m_numGroundTroops++;
				m_numFighter++;
			}
		}
	}
	
	// This alternative constructor is used to add the metrics of several players together:
	public MetricTroops(WargusPlayer p,MetricTroops m) {
		if (m!=null) {
			m_numFighter = m.m_numFighter;
			m_numArcher = m.m_numArcher;
			m_numPeasant = m.m_numPeasant;
			m_numGroundTroops = m.m_numGroundTroops;
			m_numAirTroops = m.m_numAirTroops;
			m_numOceanTroops = m.m_numOceanTroops;		
		} else {
			m_numFighter = 0;
			m_numArcher = 0;
			m_numPeasant = 0;
			m_numGroundTroops = 0;
			m_numAirTroops = 0;
			m_numOceanTroops = 0;				
		}
		
		for(WargusUnit u : p.getUnits())
		{
			if(u.getType()==WargusStateImporter.unitTypeToInteger("peasant") ||
			   u.getType()==WargusStateImporter.unitTypeToInteger("peon")) {
				m_numPeasant++;
			}
			else if(u.getType()==WargusStateImporter.unitTypeToInteger("footman") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("grunt") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("ballista") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("catapult") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("archer") ||
					u.getType()==WargusStateImporter.unitTypeToInteger("axethrower")) {
				m_numGroundTroops++;
				m_numFighter++;
			}
		}
	}	
	
}
